package financial.sharing.center.contract.service.impl;

import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.EnableStatusEnum;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.contract.dao.ContractClauseMapper;
import financial.sharing.center.contract.model.entity.ContractClause;
import financial.sharing.center.contract.service.ContractClauseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @ClassName ContractClauseServiceImpl
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/11
 * @Version 1.0
 */
@Service
public class ContractClauseServiceImpl implements ContractClauseService {

    @Autowired
    private ContractClauseMapper contractClauseMapper;

    @Override
    public PageInfo<ContractClause> getAllContractClause(Integer contractId, Integer contractDetailId) {
        Example example = new Example(ContractClause.class);
        example.createCriteria().andEqualTo("enableStatusValue", EnableStatusEnum.正常.getValue())
                                .andEqualTo("contractId",contractId)
                                .andEqualTo("contractDetailId",contractDetailId);
        List<ContractClause> contractClauseList = this.contractClauseMapper.selectByExample(example);
        return new PageInfo<>(contractClauseList);
    }

    @Override
    public Integer compileOneContractClause(ContractClause contractClause) {
        int i = this.contractClauseMapper.updateByPrimaryKey(contractClause);
        return i == 1 ? ResponseContext.成功.getValue() : ResponseContext.更新失败.getValue();
    }

    @Override
    public Integer createOneContractClause(ContractClause contractClause) {
        contractClause.setEnableStatusValue(EnableStatusEnum.正常.getValue());
        int i = this.contractClauseMapper.insert(contractClause);
        return i == 1 ? ResponseContext.成功.getValue() : ResponseContext.创建失败.getValue();
    }

    @Override
    public String createOneContractClause(Integer contractId, Integer contractDetailId, String context) {
        ContractClause contractClause = new ContractClause(contractId,contractDetailId,context);
        return null;
    }

    @Override
    public Integer deleteOneContractClause(Integer id) {
        ContractClause contractClause = this.contractClauseMapper.selectByPrimaryKey(id);
        contractClause.setEnableStatusValue(EnableStatusEnum.弃用.getValue());
        int i = this.contractClauseMapper.updateByPrimaryKey(contractClause);
        return i == 1 ? ResponseContext.成功.getValue() : ResponseContext.删除失败.getValue();
    }
}
